package cn.wolfcode.wolf2w.elasticsearch.service.impl;

import cn.wolfcode.wolf2w.elasticsearch.domain.TravelEs;
import cn.wolfcode.wolf2w.elasticsearch.repository.TravelESRepository;
import cn.wolfcode.wolf2w.elasticsearch.service.ITravelESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TravelESServiceImpl implements ITravelESService {
    @Autowired
    private TravelESRepository travelESRepository;

    @Autowired
    private ElasticsearchTemplate template;

    @Override
    public void save(TravelEs travelES) {
        travelESRepository.save(travelES);
    }

    @Override
    public void update(TravelEs travelES) {
        travelESRepository.save(travelES);
    }

    @Override
    public void delete(String id) {
        travelESRepository.deleteById(id);
    }

    @Override
    public TravelEs get(String id) {
        return travelESRepository.findById(id).orElse(null);
    }

    @Override
    public List<TravelEs> listAll() {
        Iterable<TravelEs> iterable = travelESRepository.findAll();
        ArrayList<TravelEs> list = new ArrayList<>();
        iterable.forEach(a -> list.add(a));
        return list;
    }
}